package com.rtwo.tio.client.handler;

import com.rtwo.tio.common.BasicHandler;
import com.rtwo.tio.common.SessionContext;
import com.rtwo.tio.server.handler.LoginResponseHandler;
import com.rtwo.tio.server.msg.LoginResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;

import java.io.UnsupportedEncodingException;

/**
 * Created by hasee on 2018/7/18.
 */
public class LoginRequestHandler extends BasicHandler<LoginResponse>{

    private static Logger logger = LoggerFactory.getLogger(LoginRequestHandler.class);


    @Override
    public Class<LoginResponse> getClazz() {
        return LoginResponse.class;
    }

    @Override
    public void postHanlder(LoginResponse body, ChannelContext channelContext) throws UnsupportedEncodingException {
        if(LoginResponse.SUCCESS==body.getCode()){
            channelContext.setAttribute("token",body.getToken());
            logger.error("登录成功，token是:" + body.getToken());
        }else{
            logger.error("登录失败");
        }
    }
}
